//
//  UserData.m
//  Inforcollection
//
//  Created by macbook on 15/12/9.
//  Copyright © 2015年 oceansoft.liw. All rights reserved.
//

#import "UserData.h"

@implementation UserData


+(instancetype)shareUserData
{
    static UserData *shareUser = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareUser = [[UserData alloc]init];
    });
    return shareUser;
}

-(void)saveUserInfoWith:(NSDictionary *)userInfo
{
    _isLogin = YES;
    
    _userModel = [UserModel UserModelWithDic:userInfo];
    
    [UserDefaults setBool:_isLogin forKey:KIsLogin];
    
    [UserDefaults synchronize];
}

-(void)loginOut
{
    _isLogin = NO;
    
    [UserDefaults setBool:_isLogin forKey:KIsLogin];
    
    _userModel=nil;
    
    [UserDefaults synchronize];
}

//修改过电话号码保存
//-(void)savaPhone:(NSString *)phoneNum
//{
//    [_userModel setMobile:phoneNum];
//}

//保存用户名和密码（就暂时用系统内的方法）
-(void)savaUserNameAndPassWord:(NSString *)userName WithPassWord:(NSString *)passWord
{
    [UserDefaults setObject:userName forKey:KUserName];
    [UserDefaults setObject:passWord forKey:KPassWord];
    [UserDefaults synchronize];
}

-(void)clearUserNameAndPassWord
{
    [UserDefaults setObject:nil forKey:KUserName];
    [UserDefaults setObject:nil forKey:KPassWord];
    [UserDefaults synchronize];
}

-(NSString *)getUserName
{
    return [UserDefaults objectForKey:KUserName];
}
-(NSString *)getPassWord
{
    return [UserDefaults objectForKey:KPassWord];
}
@end
